<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订单管理页面</title>
    <style>
        /* 全局样式 */
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 20px;
            background-color: #f4f7fa;
            color: #333;
        }

        /* 标题样式 */
        h1 {
            text-align: center;
            color: #2c3e50;
            margin-bottom: 30px;
            font-size: 28px;
        }

        /* 表格容器样式 */
        .table-container {
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            overflow: hidden;
        }

        /* 表格样式 */
        table {
            width: 100%;
            border-collapse: collapse;
        }

        /* 表头样式 */
        th {
            background-color: #2c3e50;
            color: #fff;
            padding: 15px;
            text-align: center;
            font-weight: 600;
            border-bottom: 2px solid #34495e;
        }

        /* 表格单元格样式 */
        td {
            padding: 15px;
            text-align: center;
            border-bottom: 1px solid #ecf0f1;
        }

        /* 表格行悬停效果 */
        tr:hover {
            background-color: #f9f9f9;
        }

        /* 分页容器样式 */
        .pagination {
            margin-top: 20px;
            text-align: center;
        }

        /* 分页按钮样式 */
        .pagination button {
            margin: 0 5px;
            padding: 10px 15px;
            cursor: pointer;
            background-color: #3498db;
            color: #fff;
            border: none;
            border-radius: 5px;
            transition: background-color 0.3s ease;
        }

        /* 分页按钮悬停效果 */
        .pagination button:hover {
            background-color: #2980b9;
        }

        /* 禁用分页按钮样式 */
        .pagination button:disabled {
            background-color: #bdc3c7;
            cursor: not-allowed;
        }

        /* 操作按钮样式 */
        .btn-action {
            padding: 8px 12px;
            background-color: #27ae60;
            color: #fff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        /* 操作按钮悬停效果 */
        .btn-action:hover {
            background-color: #2ecc71;
        }
    </style>
</head>

<body>
    <h1>订单管理</h1>
    <div class="table-container">
        <table>
            <thead>
                <tr>
                    <th>订单号</th>
                    <th>用户</th>
                    <th>商品</th>
                    <th>金额</th>
                    <th>状态</th>
                    <th>时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody id="orderTableBody">
                <!-- 订单数据将动态插入此处 -->
            </tbody>
        </table>
    </div>
    <div class="pagination" id="pagination">
        <!-- 分页按钮将动态插入此处 -->
    </div>

    <script>
        // 模拟订单数据
        const allOrders = [
            {
                orderNumber: '#20240120001',
                user: '王明',
                product: '我爸爸',
                amount: 15.00,
                status: '待发货',
                time: '2024-01-20 15:30',
                action: '处理'
            },
            {
                orderNumber: '#20240120002',
                user: '李亮',
                product: '丑小鸭',
                amount: 20.00,
                status: '已发货',
                time: '2024-01-20 14:20',
                action: '查看'
            },
            {
                orderNumber: '#20240120003',
                user: '张三',
                product: '故事书',
                amount: 30.00,
                status: '已完成',
                time: '2024-01-20 13:10',
                action: '查看详情'
            },
            {
                orderNumber: '#20240120004',
                user: '李四',
                product: '玩具车',
                amount: 50.00,
                status: '待支付',
                time: '2024-01-20 12:45',
                action: '提醒支付'
            },
            {
                orderNumber: '#20240120005',
                user: '王五',
                product: '拼图',
                amount: 25.00,
                status: '已取消',
                time: '2024-01-20 11:30',
                action: '查看记录'
            }
        ];

        const itemsPerPage = 2; // 每页显示的订单数量
        let currentPage = 1; // 当前页码

        // 渲染指定页面的订单数据
        function renderOrders(page) {
            const startIndex = (page - 1) * itemsPerPage;
            const endIndex = startIndex + itemsPerPage;
            const ordersOnPage = allOrders.slice(startIndex, endIndex);

            const tableBody = document.getElementById('orderTableBody');
            tableBody.innerHTML = '';

            ordersOnPage.forEach(order => {
                const row = document.createElement('tr');
                row.innerHTML = `
                    <td>${order.orderNumber}</td>
                    <td>${order.user}</td>
                    <td>${order.product}</td>
                    <td>￥${order.amount.toFixed(2)}</td>
                    <td><span class="status">${order.status}</span></td>
                    <td>${order.time}</td>
                    <td>
                        <button class="btn-action">${order.action}</button>
                    </td>
                `;
                tableBody.appendChild(row);
            });
        }

        // 渲染分页按钮
        function renderPagination() {
            const totalPages = Math.ceil(allOrders.length / itemsPerPage);
            const paginationDiv = document.getElementById('pagination');
            paginationDiv.innerHTML = '';

            for (let i = 1; i <= totalPages; i++) {
                const button = document.createElement('button');
                button.textContent = i;
                button.addEventListener('click', () => {
                    currentPage = i;
                    renderOrders(currentPage);
                });
                if (i === currentPage) {
                    button.disabled = true;
                }
                paginationDiv.appendChild(button);
            }
        }

        // 初始化页面
        function init() {
            renderOrders(currentPage);
            renderPagination();
        }

        init();
    </script>
</body>

</html>